package com.zhengyun.zuul.controller;

import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MyErrorController implements ErrorController {
    @Override
    public String getErrorPath() {
        return "/error"; //固定格式
    }

    @RequestMapping("/error") //覆盖掉默认的ErrorController
    public String myError(){
        RequestContext context = RequestContext.getCurrentContext();
        ZuulException exception = (ZuulException) context.getThrowable();
        return "这是自定义的全局错误页面："+ exception.nStatusCode+","+exception.getMessage();
    }

}
